<form>
    <label for="file-upload">选择图片：</label>
    <input type="file" id="file-upload" name="file-upload">
    <button type="submit">上传</button>
</form>

<script>
    const fileInput = document.getElementById('file-upload');

    fileInput.addEventListener('change', (event) => {
        const file = event.target.files[0];
        const reader = new FileReader();

        reader.addEventListener('load', (event) => {
            const imageUrl = event.target.result;
            // 在这里可以将图片URL传递到后端或在前端显示图片
        });

        reader.readAsDataURL(file);
    });
</script>